﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Ext.Net;
using Bussiness;

public partial class HotManage : BasePage
{
    Hot hot = new Hot();
    Bussiness.Store sm = new Bussiness.Store();
    protected void Page_Load(object sender, EventArgs e)
    {
        if (X.IsAjaxRequest)
        {
            return;
        }

        setContent();
    }


    private void setContent()
    {
        string storecond = string.Empty;
        if (ComboBox3.Text != "")
        {
            storecond = " storeid=" + ComboBox3.Value;
        }
        SStore.DataSource = sm.GetList("").Tables[0].DefaultView;
        SStore.DataBind();
        if (storecond.Length > 0)
        {
            Store1.DataSource = hot.GetList(storecond).Tables[0].DefaultView;
            Store1.DataBind();
        }

    }



    protected void HandleChanges(object sender, BeforeStoreChangedEventArgs e)
    {
        ChangeRecords<Hot> persons = e.DataHandler.ObjectData<Hot>();

        foreach (Hot created in persons.Created)
        {
            int tempId = created.id;
            hot.url = created.url;
            hot.img = created.img;
            hot.storeid = created.storeid;
            hot.text = created.text;
            int newId = hot.Add();

            if (Store1.UseIdConfirmation)
            {
                e.ConfirmationList.ConfirmRecord(tempId.ToString(), newId.ToString());
            }
            else
            {
                Store1.UpdateRecordId(tempId, newId);
            }

        }

        foreach (Hot deleted in persons.Deleted)
        {
            // this.DeletePerson(deleted.id);
            hot.Delete(deleted.id);
            if (Store1.UseIdConfirmation)
            {
                e.ConfirmationList.ConfirmRecord(deleted.id.ToString());
            }
        }

        foreach (Hot updated in persons.Updated)
        {
            //this.UpdatePerson(updated);
            hot.id = updated.id;
            hot.url = updated.url;
            hot.img = updated.img;
            hot.storeid = updated.storeid;
            hot.text = updated.text;
            hot.Update();
            if (Store1.UseIdConfirmation)
            {
                e.ConfirmationList.ConfirmRecord(updated.id.ToString());
            }
        }
        e.Cancel = true;
    }
    protected void Button8_DirectClick(object sender, DirectEventArgs e)
    {
        setContent();
    }
}